<template>
  <div class="mod-sys__user">
    <el-form :inline="true" :model="state.dataForm" @keyup.enter="state.getDataList()">
      <el-form-item>
        <el-input :model="state.dataForm.institutionName" placeholder="机构名" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="state.getDataList()">查询</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="state.hasPermission('sdl:institution:save')" type="primary" @click="addOrUpdateHandle()">新增</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="state.dataListLoading" :data="state.dataList" border
              @selection-change="state.dataListSelectionChangeHandle" @sort-change="state.dataListSortChangeHandle"
              style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="institutionName" label="机构名" sortable="custom" header-align="center"
                       align="center"></el-table-column>
      <el-table-column prop="institutionType" label="机构类型" sortable="custom" header-align="center" align="center">
        <template v-slot="scope">
          {{ state.getDictLabel("institution_type", scope.row.institutionType) }}
        </template>
      </el-table-column>
      <el-table-column prop="institutionAddress" label="所在地" header-align="center" align="center"></el-table-column>
      <el-table-column prop="institutionPhone" label="联系电话" header-align="center" align="center"></el-table-column>
      <el-table-column prop="institutionMailbox" label="联系邮箱" sortable="custom" header-align="center"
                       align="center"></el-table-column>
      <el-table-column prop="institutionData" label="成立日期" sortable="custom" header-align="center"
                       align="center"></el-table-column>
      <el-table-column prop="institutionCreater" label="创始人" sortable="custom" header-align="center"
                       align="center"></el-table-column>
      <el-table-column prop="institutionIntro" show-overflow-tooltip label="简介" sortable="custom"
                       header-align="center" align="center"></el-table-column>
      <el-table-column prop="institutionProevalution" label="评级" sortable="custom" header-align="center"
                       align="center">
        <template v-slot="scope">
          <el-rate
            v-model="scope.row.institutionProevalution"
            disabled
            show-score
            text-color="#ff9900"
            score-template="{value}">
          </el-rate>
        </template>
      </el-table-column>
      <el-table-column prop="isDel" label="状态" sortable="custom" header-align="center" align="center">
        <template v-slot="scope">
          <el-tag v-if="scope.row.isDel === 0" size="small" type="danger">停用</el-tag>
          <el-tag v-else size="small" type="success">正常</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="createDate" label="创建时间" sortable="custom" header-align="center" align="center"
                       width="180"></el-table-column>
      <el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
        <template v-slot="scope">
          <el-button v-if="state.hasPermission('sdl:institution:update')" type="primary" link
                     @click="addOrUpdateHandle(scope.row.institutionId)">修改
          </el-button>
          <el-button v-if="state.hasPermission('sdl:institution:delete')" type="primary" link
                     @click="state.deleteHandle(scope.row.institutionId)">删除
          </el-button>
          <el-button v-if="state.hasPermission('sdl:institutionqaq:manage')" type="primary" link
                     @click="manageAptitudeInfo(scope.row.institutionId,scope.row.institutionName)">资质管理
            </el-button>
          <el-button v-if="state.hasPermission('sdl:institutionqaq:save')" type="primary" link
                     @click="infoAddHandle(scope.row.institutionId,scope.row.institutionName)">新增资质
          </el-button>
          <el-button v-if="state.hasPermission('sdl:institutionPic:save')" type="primary" link
                     @click="infoAddPic(scope.row.institutionId,scope.row.institutionName)">新增相关图片
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="state.page" :page-sizes="[10, 20, 50, 100]" :page-size="state.limit"
                   :total="state.total" layout="total, sizes, prev, pager, next, jumper"
                   @size-change="state.pageSizeChangeHandle"
                   @current-change="state.pageCurrentChangeHandle"></el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update ref="addOrUpdateRef" @refreshDataList="state.getDataList"></add-or-update>
    <info-add ref="addInfo" @refreshDataList="state.getDataList"></info-add>
    <manage-aptitude ref="manageAptitude" @refreshDataList="state.getDataList"></manage-aptitude>
    <pic-add ref="addPic" @refreshDataList="state.getDataList"></pic-add>
  </div>
</template>

<script lang="ts" setup>
import useView from "@/hooks/useView" ;
import { reactive, ref, toRefs } from "vue";
import AddOrUpdate from "@/views/sdl/institution-add-or-update.vue";
import InfoAdd from "@/views/sdl/institutionInfo-add.vue";
import ManageAptitude from "@/views/sdl/manage-aptitude.vue";
import picAdd from "@/views/sdl/institutionInfoPic-add.vue";

const view = reactive({
  getDataListURL: "/sdl/institution/page",
  getDataListIsPage: true,
  deleteURL: "/sdl/institution",
  deleteIsBatch: true,
  exportURL: "/sdl/institution/export",
  dataForm: {
    institutionName: "",
  }
});

const state = reactive({ ...useView(view), ...toRefs(view) });

const addOrUpdateRef = ref();

const addInfo = ref();

const manageAptitude = ref();

const addPic = ref();
//机构维护
const addOrUpdateHandle = (id?: number) => {
  addOrUpdateRef.value.init(id);
};
//资质新增
const infoAddHandle = (id?: number,institutionName?:string) => {
  addInfo.value.init(id,institutionName);
};

//资质新增
const infoAddPic = (id?: number,institutionName?:string) => {
  addPic.value.init(id,institutionName);
};
//资质维护
const manageAptitudeInfo = (id?: number,institutionName?:string) => {
  manageAptitude.value.init(id,institutionName);
};
</script>
